<template>
  <div class="nav-header">
    <el-icon v-if="!isFold" class="fold-menu" @click="handleFoldClick"
      ><Fold
    /></el-icon>
    <el-icon class="fold-menu" v-else @click="handleFoldClick"
      ><Expand
    /></el-icon>
    <div class="content">
      <div>
        <HyBreadCrumb :breadcrumbInfo="breadcrumbInfo" />
      </div>
      <div>
        <userInfo></userInfo>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { Fold, Expand } from '@element-plus/icons-vue'
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'

import userInfo from './user-info.vue'
import HyBreadCrumb from '@/base-ui/breadcrumb'
import { pathMapBreadCrumbs } from '@/utils/map-menus'

export default defineComponent({
  components: {
    Fold,
    Expand,
    userInfo,
    HyBreadCrumb
  },
  emits: ['foldChange'],
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    let breadcrumbInfo: any = computed(() => {
      const route = useRoute()
      const store = useStore()
      const userMenus = store.state.loginModule.userMenus
      const path = route.path
      return pathMapBreadCrumbs(userMenus, path, (breadcrumbInfo = []))
    })

    return {
      isFold,
      handleFoldClick,
      breadcrumbInfo
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  width: 100%;
  display: flex;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    flex: 1;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
  }
}
</style>
